package com.carkeeper.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.carkeeper.pojo.ServiceTypePO;
import com.carkeeper.service.ServiceTypeService;
import com.carkeeper.vo.Pager;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/serviceType")
public class ServiceTypeController {
    @Autowired
    private ServiceTypeService serviceTypeService;
    /*
    * 查询服务分类分页
    * 将数据导入Pager分页工具，返回给前端
    * */
    @GetMapping
    public Pager<ServiceTypePO> queryPage(@RequestParam(value = "code",required = false) String code,
                                          @RequestParam(value = "name",required = false) String name,
                                          @RequestParam(value = "page",defaultValue = "1") Long page,
                                          @RequestParam(value = "pageSize",defaultValue = "10") Long pageSize){
        Page<ServiceTypePO> poPage = serviceTypeService.query(code,name,page,pageSize);
        return new Pager(poPage);
    }

    @GetMapping("/{id}")
    public ServiceTypePO getById(@PathVariable Long id){
        return serviceTypeService.findById(id);
    }

    /*
    * 新增服务分类
    * */
    @PostMapping
    public Boolean add(@RequestBody ServiceTypePO po){
        serviceTypeService.add(po);
        return true;

    }

    /*
    * 更新服务分类
    * */
    @PutMapping("/{id}")
    public Boolean update(@PathVariable long id,
                          @RequestBody ServiceTypePO po){
        serviceTypeService.update(id,po);
        return true;

    }

    /*
    * 删除服务分类
    * */
    @DeleteMapping("/{id}")
    public Boolean delete(@PathVariable long id){
        serviceTypeService.delete(id);
        return true;

    }
}
